package com.lvman.configs.instrumentation;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by jams on 2016/10/19.
 * ***
 * Tel: ***
 */

class Test {
    public static final String DAY = "DAY";
    public static final String HOUR = "HOUR";
    public static final String MINUTE = "MINUTE";
    public static final String SECOND = "SECOND";
    public static double c;

    public static void main(String[] a) {
        Test test = new Test();
        String s1 = " sd  ddd  d ";
        Map<String, String> param_map = new HashMap<>();
        param_map.put("a","b");
        param_map.put("a","cc");
        String s = "物业缴费";
        System.out.print(""+s.length());

    }


    private String removeSpace(String str) {
        return str.replace(" ", "");
    }

    Calendar stringToCalendar(String strTime) {
        // 创建 Calendar 对象
        Calendar calendar = Calendar.getInstance();
        try {
            // 对 calendar 设置时间的方法
            // 设置传入的时间格式
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date date = dateFormat.parse(strTime);
            // 对 calendar 设置为 date 所定的日期
            calendar.setTime(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return calendar;
    }

    private String setEndTime(int n, String time) {
        Calendar calendar = stringToCalendar(time);
        int month = calendar.get(Calendar.MONTH);
        int startDay = calendar.get(Calendar.DAY_OF_MONTH);
        if ((n + month) > 12) {
            calendar.add(Calendar.YEAR, 1);
            calendar.add(Calendar.MONTH, n - 12);
        } else {
            calendar.add(Calendar.MONTH, n);
        }
        int endDays = getCurrentMonthDay((new SimpleDateFormat("yyyy-MM-dd")).format(calendar.getTime()));
        int differ = startDay - endDays;//
        if (differ <= 0) {
            calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 1);
        }
        return (new SimpleDateFormat("yyyy-MM-dd")).format(calendar.getTime());
    }

    /**
     * 获取当月的 天数
     */
    private int getCurrentMonthDay(String calendar) {
        Calendar a = stringToCalendar(calendar);
        a.set(Calendar.DATE, 1);
        a.roll(Calendar.DATE, -1);
        return a.get(Calendar.DATE);
    }

    private int getMinutes(String timeType, String startTime, String endTime) {
        if (startTime == null || endTime == null) {
            return -1;
        }
        try {
            SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            long from = simpleFormat.parse(startTime).getTime();
            long to = simpleFormat.parse(endTime).getTime();
            int type = 0;
            switch (timeType) {
                case DAY:
                    type = 1000 * 60 * 60 * 24;
                    break;
                case HOUR:
                    type = 1000 * 60 * 60;
                    break;
                case MINUTE:
                    type = 1000 * 60;
                    break;
                case SECOND:
                    type = 1000;
                    break;
                default:
                    type = 1000;
                    break;
            }
            return (int) ((to - from) / type);
        } catch (Exception e) {
            System.out.print(e.getMessage());
            return -1;
        }
    }
}
